import orngClustering
import orange
import orngMDS
from pylab import scatter, show

data = orange.ExampleTable("/home/sylwek/bpythonsessions/iris")
km = orngClustering.KMeans(data, 3, minscorechange=0, maxiters=10)

euclidean = orange.ExamplesDistanceConstructor_Euclidean(data)
distance = orange.SymMatrix(len(data))
for i in range(len(data)):
    for j in range(i+1):
        distance[i, j] = euclidean(data[i], data[j])


mds=orngMDS.MDS(distance)
mds.run(100)

colors = ["red", "yellow", "blue"]

points = []
for (i,d) in enumerate(data):
    points.append((mds.points[i][0], mds.points[i][1], km.clusters[i]))
   
   
for c in range(len(set(km.clusters))):
    
    sel = filter(lambda x: x[-1]==c, points)
    x = [s[0] for s in points]
    y = [s[1] for s in points]
    scatter(x, y, c=colors[c])


show()


